package ms.shop.dao;

import mapper.MsMapper;
import ms.shop.entity.Good;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface GoodDAO extends MsMapper<Good> {

    /**
     * 查询商品列表
     * @param name
     * @param startPrice
     * @param endPrice
     * @param status
     * @return
     */
    @Select("<script>"
            + "select * from t_good "
            + "where 1=1 "
            + "<if test=\"name != null and  name!= '' \"> and name like '%${name}%' </if> "
            + "<if test=\"startPrice != 0 \"> and price &gt;= #{startPrice} </if> "
            + "<if test=\"startPrice != 0 \"> and price &lt;= #{endPrice} </if> "
            + "<if test=\"status != 0 \"> and status=#{status} </if> "
            + "order by create_time desc"
            + "</script>")
    @ResultType(Good.class)
    List<Good> queryGoods(@Param("name") String name, @Param("startPrice") Long startPrice, @Param("endPrice") Long endPrice, @Param("status") Integer status);
}
